package demo2;

import java.util.ArrayList;
import java.util.Scanner;

public class InputStu {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();

        //输入学生信息
        Scanner sc = new Scanner(System.in);
        System.out.println("输入几个学生？");
        int num = sc.nextInt();
        for (int i = 0; i < num; i++) {
            Student s = new Student();
            System.out.println("输入名字");
            String name = sc.next();
            s.setName(name);
            System.out.println("输入年龄");
            int age = sc.nextInt();
            s.setAge(age);
            //添加到集合
            list.add(s);
        }
        //输出
        for (int i = 0; i < num; i++) {
            System.out.println(list.get(i).getName() + ", " + list.get(i).getAge());
        }

    }
}
